﻿/*
 * Created by SharpDevelop.
 * User: lpelegrini
 * Date: 06/23/2013
 * Time: 16:37
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Fazenda.BLL;

namespace Fazenda
{
	/// <summary>
	/// Description of PersonForm.
	/// </summary>
	public partial class PersonForm : Form
	{
		public PersonForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		public void UpdateGrid()
        {
            // Comunicação com a Camada BLL
            PersonBLL obj = new PersonBLL();
           	dtGridPersons.DataSource = obj.GetAll();
   
            // Atualizando os objetos TextBox
            txtId.Text = dtGridPersons[0, dtGridPersons.CurrentRow.Index].Value.ToString();
            txtName.Text = dtGridPersons[1, dtGridPersons.CurrentRow.Index].Value.ToString();
            cmbCategory.SelectionStart = Int32.Parse(dtGridPersons[2, dtGridPersons.CurrentRow.Index].Value.ToString());
            cmbPersonType.SelectionStart = Int32.Parse(dtGridPersons[3, dtGridPersons.CurrentRow.Index].Value.ToString());
            txtDocument.Text = dtGridPersons[4, dtGridPersons.CurrentRow.Index].Value.ToString();
        }
			
		void CmbPersonTypeSelectedIndexChanged(object sender, EventArgs e)
		{
			if(cmbPersonType.SelectedIndex.Equals(0))
			{
				lblDocument.Text = "CPF:";
				txtDocument.Mask = "000.000.000-00";					
			}
			else
			{
				lblDocument.Text = "CNPJ:";
				txtDocument.Mask = "00.000.000/0000-00";
			}			
		}
	}
}
